<template>
	<view class="work-container">
		<uni-section title="工作模块" type="line"></uni-section>
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false">
				<!-- 			<uni-grid-item>
					<view class="grid-item-box" @click="scanCode">
						<uni-icons type="scan" size="30" color="#34C759"></uni-icons>
						<text class="text">扫码称重</text>
					</view>
				</uni-grid-item> -->
				<uni-grid-item>
					<view class="grid-item-box" @click="searchCode">
						<uni-icons type="scan" size="30" color="#34C759"></uni-icons>
						<text class="text">扫码称重</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" @click="searchCodeBlanking">
						<uni-icons type="arrow-down" size="30" color="#FF9500"></uni-icons>
						<text class="text">扫码下料</text>
					</view>
				</uni-grid-item>

				<!-- 			<uni-grid-item>
					<view class="grid-item-box" @click="gearView">
						<uni-icons type="gear" size="30" color="#007AFF"></uni-icons>
						<text class="text">设备切换</text>
					</view>
				</uni-grid-item> -->
				<uni-grid-item>
					<view class="grid-item-box" @click="filledView">
						<uni-icons type="cloud-download-filled" size="30" color="#FF9500"></uni-icons>
						<text class="text">历史记录</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>

		<showInputPop :show.sync="showPopup" title="扫码称重" label="工单号" placeholder="请输入工单号或扫码" @confirm="onConfirm"
			@close="onClose" />

		<showInputPop :show.sync="showBlanking" title="扫码下料" label="工单号" placeholder="请输入工单号或扫码"
			@confirm="onBlankingConfirm" @close="onBlankingClose" />
		<loading :show="Loading" />
	</view>
</template>

<script>
	import scanCodeUtils from '@/utils/scanCodeUtils';
	import showInputPop from '@/components/showInputPop.vue';
	import loading from '@/components/loading/loading.vue';
	import {
		toast
	} from '@/utils/common';
	import {
		getWorkDetail,
		getcheckSubMaterial
	} from '@/api/work/workDetails'
	import {
		WeighingMaster006ByBillNo
	} from '../../api/work/blanking';
	export default {
		components: {
			loading,
			showInputPop
		},

		data() {
			return {
				Loading: false,
				showPopup: false,
				showBlanking: false,
				current: 0,
				swiperDotIndex: 0,
				data: [{
					image: '/static/images/banner/banner02.jpg'
				}]
			}
		},
		methods: {


			gearView() {
				console.log('gearView')
			},
			filledView() {
				console.log('filledView')
			},

			queryWeighingMaster006ByBillNo(billNo) {
				WeighingMaster006ByBillNo(billNo).then(res => {
					this.Loading = false
					this.$tab.navigateTo(`/pages/work/blanking?billNo=${billNo}`);
				}).catch(err => {
					this.Loading = false
					toast(err.msg | '获取失败')
				})
			},


			scanCode() {
				console.log('scanCode')
				scanCodeUtils().then(res => {
					this.queryWorkDetailinfo(res.code)
				}).catch(err => {
					toast(err.message || '扫码失败')
				})
			},
			searchCode() {
				console.log('searchCode')
				this.showPopup = true
				// 这里添加工单查询逻辑
			},
			onConfirm(value) {
				console.log('输入的内容：', value);
				this.showPopup = false
				this.queryWorkDetailinfo(value)
			},
			onClose() {
				console.log('弹窗关闭');
				this.showPopup = false
			},
			queryWorkDetailinfo(workId) {
				this.Loading = true
				getWorkDetail(workId).then(res => {
					this.Loading = false
					this.$tab.navigateTo(`/pages/work/workDetails?workId=${workId}`);
				}).catch(err => {
					this.Loading = false
					toast(err.msg | '获取失败')
				})
			},




			searchCodeBlanking() {
				this.showBlanking = true
			},
			onBlankingConfirm(value) {
				console.log('输入的内容：', value);
				// getWorkDetail(workId)
				this.showBlanking = false
				this.queryWeighingMaster006ByBillNo(value)
			},
			onBlankingClose() {
				console.log('弹窗关闭');
				this.showBlanking = false
			},

			queryWorkBlankinginfo(value) {
				console.log(value, "value");
			},




		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
</style>